//
//  YHYCollectionViewCell.m
//  LANGirl
//
//  Created by 杨泓晔 on 16/3/25.
//
//

#import "YHYPicCollectionViewCell.h"

@interface YHYPicCollectionViewCell ()<UIGestureRecognizerDelegate>{
    CGFloat currentScale;
    CGFloat lastScale;
    CGRect oldFrame;    //保存图片原来的大小
    CGRect largeFrame;  //确定图片放大最大的程度
}
//@property (nonatomic,retain)UIImageView *myBackWhiteView;


@end

@implementation YHYPicCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self creatView];
    }
    return self;
}

- (void)creatView{
    //背景白本
    self.myBackWhiteView = [UIImageView new];
    self.myBackWhiteView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.myBackWhiteView];
    [self.myBackWhiteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(130 * AUTO_WIDTH);
        make.height.mas_equalTo(300 * AUTO_WIDTH);
        make.right.left.mas_equalTo(self);
        
    }];
    self.myBackWhiteView.userInteractionEnabled = YES;
    // self.myBackWhiteView.contentMode = UIViewContentModeCenter;
    // 设置初始的缩放比例
    self.myBackWhiteView.multipleTouchEnabled = YES;
    currentScale = 1;
    self.myBackWhiteView.image = self.myimage;
    // 创建UIPinchGestureRecognizer手势处理器，该手势处理器激发scaleImage:方法
    
    UIPinchGestureRecognizer* gesture = [[UIPinchGestureRecognizer alloc]
                                         
                                         initWithTarget:self action:@selector(handlePinch:)];
    
    // 为imageView添加手势处理器
    
    [self.myBackWhiteView addGestureRecognizer:gesture];
    // [UIApplication sharedApplication].statusBarHidden = YES;
    
}


//- (void)setMyimage:(UIImage *)myimage{
//    self.myBackWhiteView.image = self.myimage;
//}

/* 识别放大缩小 */
- (void)handlePinch:(UIPinchGestureRecognizer *)gestureRecognizer {
    CGPoint location = [gestureRecognizer locationInView:self];
    [self drawImageForGestureRecognizer:gestureRecognizer atPoint:location underAdditionalSituation:nil];
    gestureRecognizer.view.transform = CGAffineTransformScale(gestureRecognizer.view.transform, gestureRecognizer.scale, gestureRecognizer.scale);
    gestureRecognizer.scale = 1;
}
- (void)drawImageForGestureRecognizer:(UIGestureRecognizer *)recognizer
                              atPoint:(CGPoint)centerPoint underAdditionalSituation:(NSString *)addtionalSituation{
    
    NSString *imageName;
    
    if ([recognizer isMemberOfClass:[UITapGestureRecognizer class]]) {
        if ([addtionalSituation isEqualToString:@"singleTap"]) {
            imageName = @"tap.gif";
        }
        else if ([addtionalSituation isEqualToString:@"doubleTap"]){
            imageName = @"tap2.gif";
        }
        else if ([addtionalSituation isEqualToString:@"twoFingerTap"]){
            imageName = @"twoFingerTap.gif";
        }
        else{
            imageName = @"error.png";
        }
    }
    else if ([recognizer isMemberOfClass:[UIRotationGestureRecognizer class]]) {
        imageName = @"rotation.gif";
    }
    else if ([recognizer isMemberOfClass:[UISwipeGestureRecognizer class]]) {
        imageName = @"swipe.gif";
    }
    else if ([recognizer isMemberOfClass:[UIPinchGestureRecognizer class]]) {
        imageName = @"pinch.gif";
    }
    else if ([recognizer isMemberOfClass:[UIPanGestureRecognizer class]]) {
        imageName = @"pan.gif";
    }
    else if ([recognizer isMemberOfClass:[UILongPressGestureRecognizer class]]) {
        imageName = @"longPress.gif";
    }
    else {
        imageName = @"error.png";
    }
    
   // self.myBackWhiteView.image = self.myimage;
    self.myBackWhiteView.center = centerPoint;
    self.myBackWhiteView.alpha = 1.0;
}


// 缩放
#pragma mark - UIGestureRecognizerDelegate
//- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
//shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
//    return ![gestureRecognizer isKindOfClass:[UITapGestureRecognizer]];
//}



@end
